﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SmartOCR
{
    public class MaskCanvas : Canvas
    {
        private readonly Rectangle maskRect = new Rectangle()
        {
            Fill = Brushes.Red,
            Opacity = 0.5,
            Stroke = Brushes.Blue,
            StrokeThickness = 2,
        };

        public MaskCanvas()
        {
            this.Loaded += MaskCanvas_Loaded;
            this.Width = SystemParameters.PrimaryScreenWidth;
            this.Height = SystemParameters.PrimaryScreenHeight;
        }

        private void MaskCanvas_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Children.Add(maskRect);
        }

        public void Refresh(double width, double height, double x, double y)
        {
            if (width > 0 && height > 0)
            {
                maskRect.Width = width;
                maskRect.Height = height;
                Canvas.SetLeft(maskRect, x);
                Canvas.SetTop(maskRect, y);
            }
        }

        public void drawRect(Rect rect)
        {
            Rectangle rectangle = new Rectangle()
            {
                Width = rect.Width,
                Height = rect.Height,
                Fill = Brushes.LightGoldenrodYellow,
                Stroke = Brushes.Black,
                StrokeThickness = 3,
                Opacity = 0.3,
            };
            Canvas.SetLeft(rectangle, rect.X);
            Canvas.SetTop(rectangle, rect.Y);
            this.Children.Add(rectangle);
        }
    }
}
